package com.example.biyesheji.service.impl;

import com.example.biyesheji.mapper.ProductMapper;
import com.example.biyesheji.model.NewRecodeParam;
import com.example.biyesheji.pojo.ProductSales;
import com.example.biyesheji.service.NewRecodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Service
public class NewRecodeServiceImp implements NewRecodeService, Serializable {
    @Autowired
    private ProductMapper productMapper;


    /**
     * @Params
     * @Return @return {@link List }<{@link NewRecodeParam }>
     * @Description 获得最新新数据
     * @Throws
     * @Author xwh
     * @Date 2023/02/10
     */
    @Override
    public List<NewRecodeParam> getNewRecode() {
        List<NewRecodeParam> list = new ArrayList<>();
        List<ProductSales> productSales = productMapper.newRecodeLsit().subList(0,6);
        for (ProductSales param: productSales){
            NewRecodeParam newRecodeParam = new NewRecodeParam();
            String str = "编号为:"+param.getUserId()+"购买了价值"+param.getPrice()+"元的"+param.getBrand()+"牌"+param.getCategoryCode();
            newRecodeParam.setSentence(str);
            newRecodeParam.setTime(param.getEventTime());
            list.add(newRecodeParam);
        }
        return list;
    }
}
